package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysExperts;
import com.ruoyi.system.service.ISysExpertsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专家资料Controller
 * 
 * @author riddou
 * @date 2022-04-11
 */
@RestController
@RequestMapping("/system/experts")
public class SysExpertsController extends BaseController
{
    @Autowired
    private ISysExpertsService sysExpertsService;

    /**
     * 查询专家资料列表
     */
    @PreAuthorize("@ss.hasPermi('system:experts:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysExperts sysExperts)
    {
        startPage();
        List<SysExperts> list = sysExpertsService.selectSysExpertsList(sysExperts);
        return getDataTable(list);
    }

    /**
     * 导出专家资料列表
     */
    @PreAuthorize("@ss.hasPermi('system:experts:export')")
    @Log(title = "专家资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysExperts sysExperts)
    {
        List<SysExperts> list = sysExpertsService.selectSysExpertsList(sysExperts);
        ExcelUtil<SysExperts> util = new ExcelUtil<SysExperts>(SysExperts.class);
        util.exportExcel(response, list, "专家资料数据");
    }

    /**
     * 获取专家资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:experts:query')")
    @GetMapping(value = "/{expertId}")
    public AjaxResult getInfo(@PathVariable("expertId") Long expertId)
    {
        return AjaxResult.success(sysExpertsService.selectSysExpertsByExpertId(expertId));
    }

    /**
     * 新增专家资料
     */
    @PreAuthorize("@ss.hasPermi('system:experts:add')")
    @Log(title = "专家资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysExperts sysExperts)
    {
        return toAjax(sysExpertsService.insertSysExperts(sysExperts));
    }

    /**
     * 修改专家资料
     */
    @PreAuthorize("@ss.hasPermi('system:experts:edit')")
    @Log(title = "专家资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysExperts sysExperts)
    {
        return toAjax(sysExpertsService.updateSysExperts(sysExperts));
    }

    /**
     * 删除专家资料
     */
    @PreAuthorize("@ss.hasPermi('system:experts:remove')")
    @Log(title = "专家资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expertIds}")
    public AjaxResult remove(@PathVariable Long[] expertIds)
    {
        return toAjax(sysExpertsService.deleteSysExpertsByExpertIds(expertIds));
    }
}
